#pragma once



#include "stdafx.h"
#include "PairTrade.h"
#include <vector>


class PairTradeDataModel
{
	int	m_LookupTime;
	int m_RowMultiplier;

public:
	PairTradeDataModel()
		:m_RowMultiplier(0)
		,m_LookupTime(0)
	{
		InitDataModel();
	}
	std::vector<PairTrade> m_Records;
	void InitDataModel()
	{
		m_Records.clear();
		if (m_RowMultiplier > 1)
		{
			std::vector<PairTrade> rowset(m_Records);
			m_Records.reserve((m_RowMultiplier-1) * rowset.size());
			for(int i = 0 ; i < m_RowMultiplier ; ++i)
			{
				m_Records.insert(m_Records.end(), rowset.begin(), rowset.end());
			}
		}
	}

	CString GetCellText(size_t lookupId, int col) const
	{
		if (lookupId >= m_Records.size())
		{
			static CString oob(_T("Out of Bound"));
			return oob;
		}
		// How many times should we search sequential for the row ?
		for(int i=0; i < m_LookupTime; ++i)
		{
			for(size_t rowId = 0; rowId < m_Records.size(); ++rowId)
			{
				if (rowId==lookupId)
					break;
			}
		}
		return m_Records.at(lookupId).GetCellText(col, false);
	}

	size_t GetRowIds() const { return m_Records.size(); }
	int GetColCount() const { return PairTrade().GetColCount(); }
	CString GetColTitle(int col) const { return PairTrade().GetCellText(col, true); }

	std::vector<PairTrade>& GetRecords() { return m_Records; }
	void SetLookupTime(int lookupTimes) { m_LookupTime = lookupTimes; }
	void SetRowMultiplier(int multiply) { if (m_RowMultiplier != multiply ) { m_RowMultiplier = multiply; InitDataModel(); } }
};